class Solution(object):
    def longestSubarray(self, nums):
        last0 = 0
        last1 = -1
        max_len = 0
        for num in nums:
            if num == 1:
                last0 += 1
                last1 += 1
            else:
                last1 = last0
                last0 = 0
            max_len = max(max_len, last0 - 1, last1)
        return max_len